/**
 * Created by Administrator on 2016/12/7.
 */

function resHandler(res) {
  $(res.data).each(function (i, key) {
    key.ctime = getRecordDate(key.ctime);
    key.isValid = key.isValid == 0 ? '未启用' : '已启用';
    key.userRole = roleObj[key.userRole];
    key.accType = accTypeObj[key.accType];
  });
  var a = {
    rows: res.data
  };
  return a;
}
function closeWindow() {
  $('.view-datails').css("display", "none")
}
//function myQueryParams(params) {
//    console.log(params);
//    return params;
//}

function emptyCondition() {
  $("#account,#lesseeName,#lesseeNum,#startDate,#endDate,#accountNum").val("");
  $("#userRole,#accountType").val("");
}

//$('.view-container').load('tpl/loginadmin.html', function () {
//    $('#loginData').bootstrapTable({
//        url: 'data/data2.json'
//    })
//});

function compile(data) {
  $('.details [data-name]').each(function (i, elem) {
    $(elem).html(data[$(elem).attr('data-name')]);

  });

  $("#compile").click(function () {
    //var msg = {}
    //$(".detail-table td").each(function (i, value) {
    //  msg[$(value).attr("id")] = $(value).val()
    //})
    //console.log(msg.accountNum)
    // $.getJSON('url',msg,function(){})
    $(".modle-show").load("tpl/popupframe/compile-details.html",
        function () {
          cancelCompile(data);
        });
  })
}

function cancelCompile(data) {
  console.log(data);
  var accType = data.accType;
  $(".compile-details [data-name]").each(function (i, elem) {
    console.log(elem);
    elem.nodeName == "INPUT" ? (
        $(elem).val(data[$(elem).attr("data-name")])
    ) : (
        elem.nodeName == "SELECT" ?
            $(elem).children('[value="accTpe"]').prop('select', 'true') :
            $(elem).html(data[$(elem).attr("data-name")])
    );
  });
  $("#cancelCompile").click(function () {
    $(".modle-show").load("tpl/popupframe/details.html", function () {
      compile(data);
    })
  })
}

/* 条件选择查找 */
function conditionFind() {
  var userRole = $("#userRole").val();
  var accountType = $("#accountType").val();
  var condition = {};
  condition.userRole = userRole;
  condition.accountType = accountType
  $(".condition input").each(function (i, inputValue) {
    condition[$(inputValue).attr("id")] = $(inputValue).val()
  })
  console.log(condition.lesseeNum)
  //$.post("url",condition,function(data){})
}
/* 资料修改提交 */
function submitAmend() {
  var msg = {};
  $(".compile-details input").each(function (i, inputValue) {
    msg[$(inputValue).attr("id")] = $(inputValue).val()
  });
  console.log(msg);
  //$.post("url",msg,function(data){})
}
function operate(obj) {
  if (obj.value == "批量操作") {
    obj.value = "取消操作";
    $(".bs-checkbox").show();
    $("#loginData").bootstrapTable("resetView");
    $(".fixed-table-container").append("<div id='btn-groups'>\
        <input type='button' class='btn btn-success' value='启用'>\
        <input type='button' class='btn btn-info' value='停用'>\
        <input type='button' class='btn btn-warning' value='打印'>\
        <input type='button' class='btn btn-danger' value='删除'>\
        <input type='button' class='btn btn-primary' value='下载'>\
        </div>")
  }
  else {
    obj.value = "批量操作";
    $(".bs-checkbox").hide();
    $("#loginData").bootstrapTable("resetView");
    $("#btn-groups").remove();
  }
}

function isValidSelector() {
  $('.radio-style label')[0].querySelector('img').setAttribute('src', '../../../img/radioafter.png');
  var isValid = $('.radio-style [name="state"]')[0].getAttribute('value');
  $('.radio-style label').click(function () {
    $('.radio-style label').children('img').attr('src', '../../../img/radiobefore.png');
    $(this.querySelector('img')).attr('src', '../../../img/radioafter.png');
    isValid = $('#' + $(this).attr('for')).val();
    console.log(isValid);
  })
  console.log(isValid);
}

/*
 function changeImg(){

 }*/

// 仅选择日期
$(".form-date").datetimepicker(
    {
      language: "zh-CN",
      weekStart: 1,
      todayBtn: 1,
      autoclose: 1,
      todayHighlight: 1,
      startView: 2,
      minView: 2,
      forceParse: 0,
      format: "yyyy-mm-dd"
    });

